#include <iostream>

using namespace std;
typedef long long LL;

LL a, b, p;

LL qpow()
{
	LL ret = 0;
	while(b)
	{
		if (b&1) ret = (ret+a)%p;
		a = (a+a)%p;
		b >>= 1;
	}
	
	return ret;
}

int main()
{
	cin >> a >> b >> p;
	
	cout << qpow() << endl;
	
	return 0;
} 
